/*     */ package com.newcrm.db;
/*     */ 
/*     */ import com.newcrm.config.Config;
/*     */ import com.newcrm.exception.DBException;
/*     */ import java.sql.Connection;
/*     */ import java.sql.SQLException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.apache.commons.dbutils.DbUtils;
/*     */ import org.apache.commons.dbutils.GenKeyQueryRunner;
/*     */ import org.apache.commons.dbutils.MyMapListHandler;
/*     */ import org.apache.commons.dbutils.QueryRunner;
/*     */ import org.apache.commons.dbutils.handlers.ScalarHandler;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class NoteDefaultWordManager
/*     */ {
/*  23 */   private static Logger logger = Logger.getLogger(NoteDefaultWordManager.class.getName());
/*     */ 
/*     */   public List<Map<String, Object>> list(int companyId)
/*     */     throws DBException, SQLException
/*     */   {
/*  35 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  36 */     if (conn == null) {
/*  37 */       throw new DBException();
/*     */     }
/*  39 */     QueryRunner runner = new QueryRunner();
/*     */     try {
/*  41 */       return (List)runner.query(conn, "SELECT DefaultWordId,DefaultWord FROM T_Note_Default_Word WHERE CompanyId = ? ORDER BY OrderNum ASC", 
/*  42 */         new MyMapListHandler(), new Object[] { Integer.valueOf(companyId) });
/*     */     } finally {
/*     */       try {
/*  45 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/*  47 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   public void init(int companyId, String userId)
/*     */   {
/*  59 */     if (companyId < 0) {
/*  60 */       return;
/*     */     }
/*     */ 
/*  63 */     Config config = Config.getInstance();
/*  64 */     String[] words = config.noteDefaultWord;
/*  65 */     if ((words != null) && (words.length > 0)) {
/*  66 */       Connection conn = ConnectionManager.getInstance().getConnection();
/*  67 */       if (conn == null) {
/*  68 */         return;
/*     */       }
/*  70 */       QueryRunner runner = new QueryRunner();
/*     */       try {
/*  72 */         List baseParams = new ArrayList();
/*  73 */         for (String word : words) {
/*  74 */           if ((word != null) && (word.trim().length() != 0))
/*     */           {
/*  77 */             List info = new ArrayList();
/*  78 */             info.add(Integer.valueOf(companyId));
/*  79 */             info.add(word);
/*  80 */             info.add(userId);
/*  81 */             info.add(userId);
/*  82 */             baseParams.add(info.toArray(new Object[0]));
/*     */           }
/*     */         }
/*  85 */         runner.batch(conn, "INSERT INTO T_Note_Default_Word (CompanyId, DefaultWord, CreateDate, UpdateDate, CreateUserId, UpdateUserId) values (?, ?, NOW(), NOW(),?, ?) ", 
/*  86 */           (Object[][])baseParams.toArray(new Object[0][]));
/*     */       } catch (SQLException e) {
/*  88 */         logger.warn("add default word failed", e);
/*     */         try
/*     */         {
/*  91 */           DbUtils.close(conn);
/*     */         } catch (SQLException se) {
/*  93 */           logger.warn("close conn failed", e);
/*     */         }
/*     */       }
/*     */       finally
/*     */       {
/*     */         try
/*     */         {
/*  91 */           DbUtils.close(conn);
/*     */         } catch (SQLException e) {
/*  93 */           logger.warn("close conn failed", e);
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   public int add(String defaultword, int companyId, String userId)
/*     */   {
/* 108 */     if ((defaultword == null) || (defaultword.length() == 0)) {
/* 109 */       return -1;
/*     */     }
/* 111 */     if (companyId < 0) {
/* 112 */       return -1;
/*     */     }
/*     */ 
/* 115 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 116 */     if (conn == null) {
/* 117 */       return -1;
/*     */     }
/*     */ 
/* 120 */     GenKeyQueryRunner runner = new GenKeyQueryRunner(
/* 121 */       new ScalarHandler(), new String[] { "DefaultWordId" });
/*     */     try {
/* 123 */       runner.update(conn, "INSERT INTO T_Note_Default_Word (CompanyId, DefaultWord, CreateDate, UpdateDate, CreateUserId, UpdateUserId) values (?, ?, NOW(), NOW(),?, ?) ", new Object[] { Integer.valueOf(companyId), 
/* 124 */         defaultword, userId, userId });
/* 125 */       return ((Long)runner.getGeneratedKeys()).intValue();
/*     */     } catch (SQLException e) {
/* 127 */       logger.warn("create default word failed", e);
/*     */     } finally {
/*     */       try {
/* 130 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/* 132 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/* 135 */     return -1;
/*     */   }
/*     */ 
/*     */   public int update(int defaultWordId, String defaultWord, String userId)
/*     */   {
/* 147 */     if (defaultWordId < 0) {
/* 148 */       return 0;
/*     */     }
/*     */ 
/* 151 */     if ((defaultWord == null) || (defaultWord.length() == 0)) {
/* 152 */       return 0;
/*     */     }
/*     */ 
/* 155 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 156 */     if (conn == null) {
/* 157 */       return -1;
/*     */     }
/* 159 */     QueryRunner runner = new QueryRunner();
/*     */     try {
/* 161 */       return runner.update(conn, "UPDATE T_Note_Default_Word SET DefaultWord = ?, UpdateDate = NOW(), UpdateUserId = ? WHERE DefaultWordId = ?", new Object[] { 
/* 162 */         defaultWord, userId, Integer.valueOf(defaultWordId) });
/*     */     } catch (SQLException e) {
/* 164 */       logger.warn("update default word failed", e);
/*     */     } finally {
/*     */       try {
/* 167 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/* 169 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/* 172 */     return 0;
/*     */   }
/*     */ 
/*     */   public int delete(int defaultWordId)
/*     */   {
/* 182 */     if (defaultWordId < 0) {
/* 183 */       return 0;
/*     */     }
/*     */ 
/* 186 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 187 */     if (conn == null) {
/* 188 */       return -1;
/*     */     }
/*     */ 
/* 191 */     QueryRunner runner = new QueryRunner();
/*     */     try
/*     */     {
/* 194 */       return runner.update(conn, "DELETE FROM T_Note_Default_Word WHERE DefaultWordId = ?", 
/* 195 */         Integer.valueOf(defaultWordId));
/*     */     } catch (SQLException e) {
/* 197 */       logger.warn("delete default word failed", e);
/*     */     } finally {
/*     */       try {
/* 200 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/* 202 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/* 205 */     return 0;
/*     */   }
/*     */ 
/*     */   public int updateSort(int id, int order, String userId)
/*     */   {
/* 217 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 218 */     if (conn == null) {
/* 219 */       return 0;
/*     */     }
/* 221 */     QueryRunner runner = new QueryRunner();
/*     */     try
/*     */     {
/* 224 */       return runner.update(conn, "UPDATE T_Note_Default_Word SET OrderNum = ? , UpdateDate = NOW(), UpdateUserId = ? WHERE DefaultWordId = ?", new Object[] { 
/* 225 */         Integer.valueOf(order), userId, Integer.valueOf(id) });
/*     */     } catch (SQLException e) {
/* 227 */       logger.warn("update order failed", e);
/*     */     } finally {
/*     */       try {
/* 230 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/* 232 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/* 235 */     return 0;
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.db.NoteDefaultWordManager
 * JD-Core Version:    0.6.1
 */